package com.hn.gege.sys.modules.sys.dto;

import com.google.common.base.Converter;
import com.hn.gege.sys.modules.sys.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDate;

@Data
@ApiModel(value = "UserBaseDTO对象", description = "用户基础信息DTO")
public class UserBaseDTO {

    @ApiModelProperty(value = "id", required = true)
    private String id;

    @ApiModelProperty(value = "姓名")
    private String realname;

    @ApiModelProperty(value = "性别")
    private String sex;

    @ApiModelProperty(value = "昵称")
    private String nickname;

    @ApiModelProperty(value = "头像")
    private String headImg;

    @ApiModelProperty(value = "出生日期")
    private LocalDate dateOfBirth;

    @ApiModelProperty(value = "地址省")
    private String addressProvince;

    @ApiModelProperty(value = "地址市")
    private String addressCity;

    @ApiModelProperty(value = "地址县")
    private String addressCounty;

    @ApiModelProperty(value = "地址详细")
    private String addressDetail;

    @ApiModelProperty(value = "机构代码")
    private String orgCode;

    
    public User convertToUser(){
        UserBaseDTOConver userBaseDTOConver = new UserBaseDTOConver();
        User user = userBaseDTOConver.doForward(this);
        return user;
    }
    public UserBaseDTO convertFor(User user){
        UserBaseDTOConver userBaseDTOConver = new UserBaseDTOConver();
        UserBaseDTO userBaseDTO = userBaseDTOConver.doBackward(user);
        return userBaseDTO;
    }
    
    public static class UserBaseDTOConver extends Converter<UserBaseDTO, User> {
    
        @Override
        protected User doForward(UserBaseDTO userBaseDTO) {
            User user = new User();
            BeanUtils.copyProperties(userBaseDTO, user);
            return user;
        }
    
        @Override
        protected UserBaseDTO doBackward(User user) {
            UserBaseDTO userBaseDTO = new UserBaseDTO();
            BeanUtils.copyProperties(user, userBaseDTO);
            return userBaseDTO;
    
        }
    }
}
